package com.leenmvc.core.dao.communal;

import com.leenmvc.core.aop.proxy.ProxyBaseDao;
import com.leenmvc.core.aop.proxy.ProxyUtil;
import com.leenmvc.core.dao.mysql.MysqlAfterExcute;
import com.leenmvc.core.dao.mysql.MysqlBaseDaoImpl;
import com.leenmvc.core.dao.mysql.MysqlBeforeExcute;
import com.leenmvc.core.dao.mysql.connect.MysqlConnectionFactory;
import com.leenmvc.core.dao.mysql.wrapper.MysqlWrapperFactory;
import com.leenmvc.core.dao.sqlServer.SqlServerAfterExcute;
import com.leenmvc.core.dao.sqlServer.SqlServerBaseDaoImpl;
import com.leenmvc.core.dao.sqlServer.SqlServerBeforeExcute;
import com.leenmvc.core.dao.sqlServer.connect.SqlServerConnectionFactory;
import com.leenmvc.core.dao.sqlServer.wrapper.SqlServerWrapperFactory;

/**
 * 方言根据实体的dialect属性获取对应的持久层Dao
 *
 */
public enum  Dialect {

    MYSQL(1,
            ProxyUtil.getProxy(new ProxyBaseDao(MysqlBaseDaoImpl.getInstance(), new MysqlBeforeExcute(),new MysqlAfterExcute())),
            new MysqlWrapperFactory(),
            new MysqlConnectionFactory()
    ),
    SQL_SERVER(2, ProxyUtil.getProxy(new ProxyBaseDao(SqlServerBaseDaoImpl.getInstance(), new SqlServerBeforeExcute(), new SqlServerAfterExcute())),
            new SqlServerWrapperFactory(),
            new SqlServerConnectionFactory()),
    ORACLE(3, null, null, null) ;

    /**
     * 方言对应的ORM
     */
    private BaseDao baseDao;

    /**
     * 方言编号
     */
    private int num;

    /**
     * Wrapper工厂
     */
    private WrapperFactory wrapperFactory;

    private ConnectionFactory connectionFactory;

    private BaseDao beforeExcute;

    private BaseDao afterExcute;

    Dialect(int num , BaseDao baseDao, WrapperFactory wrapperFactory, ConnectionFactory connectionFactory) {
        this.num = num;
        this.baseDao = baseDao;
        this.wrapperFactory = wrapperFactory;
        this.connectionFactory = connectionFactory;
    }

    public BaseDao getBaseDao() {
        return baseDao;
    }

    public void setBaseDao(BaseDao baseDao) {
        this.baseDao = baseDao;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public WrapperFactory getWrapperFactory() {
        return wrapperFactory;
    }

    public void setWrapperFactory(WrapperFactory wrapperFactory) {
        this.wrapperFactory = wrapperFactory;
    }

    public BaseDao getBeforeExcute() {
        return beforeExcute;
    }

    public void setBeforeExcute(BaseDao beforeExcute) {
        this.beforeExcute = beforeExcute;
    }

    public BaseDao getAfterExcute() {
        return afterExcute;
    }

    public void setAfterExcute(BaseDao afterExcute) {
        this.afterExcute = afterExcute;
    }

    public ConnectionFactory getConnectionFactory() {
        return connectionFactory;
    }

    public void setConnectionFactory(ConnectionFactory connectionFactory) {
        this.connectionFactory = connectionFactory;
    }
}
